# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : p14.py
# @Time     : 2024/5/9 23:19
# @Author   : Robot-Zsj
"""
description:

会议室占用时间

https://blog.csdn.net/qfc_128220/article/details/134939442

i:
4
1 4
2 5
7 9
14 18

o:
1 5
7 9
14 18
"""


def merge(roomTimes):
    roomTimes.sort(key=lambda x: x[0])

    ans = []

    pre = roomTimes[0]
    for i in range(1, len(roomTimes)):
        cur = roomTimes[i]
        if pre[1] >= cur[0]:
            pre[1] = max(cur[1], pre[1])
        else:
            ans.append(pre)
            pre = cur
    ans.append(pre)
    return ans


n = int(input())

roomTimes = []

for _ in range(n):
    roomTimes.append(list(map(int, input().split())))

for start, end in merge(roomTimes):
    print(f"{start} {end}")
